package yja.gzw.app.fragmentview

import android.content.Intent
import android.widget.Toast
import androidx.lifecycle.Observer
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CircleCrop
import com.bumptech.glide.request.RequestOptions
import yja.gzw.app.R
import yja.gzw.app.activity.BianjiagerengActivity
import yja.gzw.app.activity.ChengjieActivity
import yja.gzw.app.activity.FabidingdanActivity
import yja.gzw.app.activity.HuiyuanzhongxingActiviry
import yja.gzw.app.activity.KaipianguanliActivity
import yja.gzw.app.activity.ShezhiActivity
import yja.gzw.app.activity.ShipingbaoActivity
import yja.gzw.app.activity.ShipingjianjiActivity
import yja.gzw.app.activity.WDYuerActivity
import yja.gzw.app.activity.WodefabuActivity
import yja.gzw.app.activity.WodehaoyouActiviry
import yja.gzw.app.activity.WodeshoucangActivity
import yja.gzw.app.activity.WodezhanghuaActivity
import yja.gzw.app.activity.WodezhanghuasActivity
import yja.gzw.app.base.BaseFragment
import yja.gzw.app.databinding.FragmentWodeBinding
import yja.gzw.app.model.UserData
import yja.gzw.app.viewmodel.Mainviewmodel

class WodeFragment :BaseFragment<Mainviewmodel, FragmentWodeBinding>(R.layout.fragment_wode){

    override fun onResume() {
        super.onResume()
        viewmodel.onwodezhuyewang(UserData.token,mapOf("id" to ""))

        viewmodel.onwodetongjiwang(UserData.token)

    }

    override fun initView() {
        binding.jianjishiping.setOnClickListener {
            val intent=Intent(context,ShipingjianjiActivity::class.java)
            startActivity(intent)



        }

        binding.kaifazhipiao.setOnClickListener {
            val intent=Intent(context, KaipianguanliActivity::class.java)
            startActivity(intent)
        }
        binding.wodeshoucang.setOnClickListener {
            val intent=Intent(context,WodeshoucangActivity::class.java)
            startActivity(intent)


        }

        binding.wodezhanghu.setOnClickListener {
            val intent=Intent(context, WodezhanghuasActivity::class.java)
            startActivity(intent)


        }
        binding.shipingbao.setOnClickListener {
            val intent=Intent(context,ShipingbaoActivity::class.java)
            startActivity(intent)
        }
        binding.touxiang.setOnClickListener {
            val intent=Intent(context,BianjiagerengActivity::class.java)
            startActivity(intent)

        }

        binding.shuliang.setOnClickListener {
            val intent=Intent(context,WodehaoyouActiviry::class.java)
            context?.startActivity(intent)
        }
        binding.wodeyuer.setOnClickListener {
            val intent=Intent(context,WDYuerActivity::class.java)
            context?.startActivity(intent)

        }

        viewmodel.onwodezhuyewang(UserData.token,mapOf("id" to ""))

        viewmodel.onwodetongjiwang(UserData.token)

        binding.shezhi.setOnClickListener {
            val inten=Intent(context,ShezhiActivity::class.java)
            startActivity(inten)


        }
        binding.wodefabu.setOnClickListener {

            val intent=Intent(context, WodefabuActivity::class.java)
            context?.startActivity(intent)
        }
        binding.fabudingdan.setOnClickListener {
            val intent=Intent(context, FabidingdanActivity::class.java)
            context?.startActivity(intent)



        }

        binding.huiyuanzhiongxing.setOnClickListener {
            val inten=Intent(context, HuiyuanzhongxingActiviry::class.java)
            context?.startActivity(inten)

        }
        binding.chengjiedingdan.setOnClickListener {
            val intent=Intent(context, ChengjieActivity::class.java)
            context?.startActivity(intent)


        }


    }

    override fun dataObservese() {
        viewmodel.onwodetongji.observe(this, Observer {
            if(it.code==1){

                binding.wodefabushu.text="我发布的 "+it.data.publish_count
                binding.fabudingdanshu.text="发布订单 "+it.data.publish_order_count
                binding.chengjiedingdanshu.text="承接订单 "+it.data.take_order_count

            }else{
                Toast.makeText(context,it.msg, Toast.LENGTH_SHORT).show()

            }

        })

        viewmodel.onwodezhuye.observe(this, Observer {
            if(it.code==1){
                binding.name.text=it.data.nickname
                if(it.data.avatar==""){
                    binding.touxiang.setImageResource(R.mipmap.touxiang)
                }else{
                    val requestOptions = RequestOptions.bitmapTransform(CircleCrop())
                    Glide.with(requireContext()).load("http://117ai.32.hzgqapp.com/"+it.data.avatar)
                        .apply(requestOptions)
                        .into(binding.touxiang)
                }
                binding.shuliang.text=""+it.data.fav_count+"获赞     "+it.data.fans_count+"粉丝     "+it.data.focus_count+"关注"
                binding.idzhanshi.text="ID: "+it.data.id.toString()
            }


        })


    }
}